﻿using Library.Domain;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.Domain
{
    public class AppUser : IdentityUser, IBaseEntity<string>
    {
        public AppUser()
        {
            BrokenRules = new List<ValidationRule>();
        }

        [NotMapped]
        public string Password { get; set; }

        private List<ValidationRule> _brokenRules;
        [NotMapped]        
        public virtual List<ValidationRule> BrokenRules
        {
            get { return _brokenRules; }
            set { _brokenRules = value; }
        }
        
        public bool Validate()
        {
            BrokenRules.Clear();
            ValidateNotADemoUser();

            var isValid = (BrokenRules.Count == 0);
            return isValid;
        }

        private void ValidateNotADemoUser()
        {
            if (UserName.Equals("demo"))                            
                BrokenRules.Add(new Library.Domain.ValidationRule("Demo", string.Format("User \"{0}\" can't be modified. It's used for demos.", this.UserName)));
        }
    }
}
